<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<link rel="stylesheet" href="../css/mui.min.css">
		<link href="../css/style.css" rel="stylesheet" />
		<!--common---start-->
		<script src="../js/angular/angular.min.js"></script>
		<script src="../js/angular/angular-resource.js"></script>
		<script src="../js/angular/common.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/common.js"></script>
		<!--common---end-->
		<style type="text/css">
			[ng-cloak]{display:none;}
		</style>
<style>
			#div {
				width: 0px;
				height: 0px;
				background: red;
				position: fixed;
				top: 15%;
				right: 0px;
			}
			/*移除底部或顶部三角,需要在删除此代码*/
			
			.mui-popover .mui-popover-arrow:after {
				width: 0px;
			}
			
			.shape {
				text-align: center;
				padding-bottom: 10px;
			}
			
			.shape h5 {
				line-height: 30px;
				margin-top: 10px;
				 color:#000
			}
			
			.shape p {
				text-align: center;
				padding: 2px 10px;
				width: 80%;
				border: 1px solid #f55375;
				margin: 10%;
				border-radius: 4px;
				color: #f55375;
				font-size:12px;
			}
			
			.shape p.active {
				background: #f55375;
				color: #fff;
			}
		</style>
	</head>

	<body ng-app="mainApp" ng-controller="goodsCtrl" ng-cloak>
		<header class="mui-bar mui-bar-nav mui-bar-in">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<div class="mui-input-row mui-search ">
				<input type="search" class="mui-input-clear" placeholder="" id="searchTitle">
			</div>
			<a class="mui-icon mui-pull-right right" ng-click="searchBtnClick()">搜索</a>
		</header>
		
		<div class="mui-content">
			<div class="notice_wrap">
				<div class="notice">
					<div class="notice_tit"><i class="mui-icon mui-icon-extra mui-icon-extra-notice" ></i>{{currUrl}}
					</div>
					<!--<a ng-click="openPx()" class="mui-pull-right" style="font-size: 14px; color: #c82749;position: absolute; right:0;"><i class="mui-icon mui-icon-star" style=" font-size:18px; "></i> 品型<i class="mui-icon mui-icon-star" style=" font-size:18px; "></i></a>-->
				</div>
			</div>
			
			<div id="slider" class="mui-slider mui-fullscreen list_tab">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll aaa" id="stylePar">
						<a class="mui-control-item" name="{{item.id}}" ng-class="{'mui-active':initIndex==$index}" val="{{$index}}" href="#{{item.id}}" ng-repeat="item in topList">
							{{item.typeName}}
						</a>
					</div>
				</div>
				<div class="mui-slider-group">
					<div id="{{item.id}}"  ng-repeat="item in topList" class="mui-slider-item mui-control-content " ng-class="{'mui-active':initIndex==$index}" on-finish-render-filters>
						<div  class="mui-scroll-wrapper">
							<div class="mui-scroll" id="{{item.id}}_scroll">
								<div class="mui-content pro_con">
									<ul class="mui-table-view mui-grid-view">
										<li class="mui-table-view-cell mui-media mui-col-xs-12"   ng-show="item.pxList.length>0">
											<div  class=" shape " style="height:auto;background-color:rgba(255,255,255,1); max-height: 400px; overflow: auto;">
												<div class="mui-popover-arrow"></div>  
									            <div>
									            	<h5>— 品型选择 —</h5>
									            	<p ng-click="checkPx()" style="float: left;width: auto;margin: 5px;">
														全部
													</p>

													<p style="float: left;width: auto;margin: 5px;" ng-repeat="px in item.pxList" ng-click="checkPx(px.id)" >
														{{px.title}}
													</p>
									            </div>
											</div>
										</li>
										<li class="mui-table-view-cell mui-media mui-col-xs-6" ng-repeat="goods in item.goodsList"  ng-click="goodsDetailPage(goods.id)" >
											<a href="#">
												<img ng-if="goods.iconUrl!=undefined&&goods.iconUrl!=''" class="mui-media-object" src="{{baseUrl+'/dapi/download/getImageIO?imgUrl='+goods.iconUrl|getImgUrl}}">
												<!--<img ng-if="goods.iconUrl!=undefined&&goods.iconUrl!=''" class="mui-media-object" ng-src="{{baseUrl}}/dapi/download/getImageIO?imgUrl={{goods.iconUrl}}"></img>-->
												<img ng-if="goods.iconUrl==undefined||goods.iconUrl==''" class="mui-media-object" ng-src="../images/goodsDefault.gif">
												<div class="mui-media-body">{{goods.title}}</div>
											</a>
										</li>
									</ul>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div id="popover" class="mui-popover shape " style="height:auto;width:120px; background-color:rgba(255,255,255,1); max-height: 400px; overflow: auto;">
            <div class="mui-popover-arrow"></div>  
            <div>
            	<h5>— 品型选择 —</h5>
				<p  ng-click="checkPx(px.id)"  ng-repeat="px in pxList" >
					{{px.title}}
				</p>
            </div>
        </div>  
         <div id="div"></div>
		<script src="../js/service/goodsService.js"></script>
		<script src="../js/service/agentService.js"></script>
		<script src="../js/mui.min.js"></script>
		<script src="../js/mui.pullToRefresh.js"></script>
		<script src="../js/mui.pullToRefresh.material.js"></script>
		<script>
			mainApp.controller('goodsCtrl', function($scope, $http,goodsService,agentService) {
				mui.plusReady(function(){
					var self = plus.webview.currentWebview();
				    var gtype=self.gtype;
				    var type=self.type;
				    $scope.gtype=gtype;
			    	$scope.type=type;
			    	$scope.currUrl=self.currUrl;
				    getInitGoodsList();
				});
				$scope.index=0;
			   // $scope.currUrl="黄金";
				$scope.baseUrl=baseUrl;
				$scope.pageSize=8;
				
				var getInitGoodsList=function(){
					$scope.param={};
						if($scope.type==undefined||$scope.type==""){
							$scope.pId=$scope.gtype;
							$scope.param.typeOne=$scope.gtype;
						}else{
							$scope.pId=$scope.type;
							$scope.param.type=$scope.type;
							$scope.param.typeOne=$scope.gtype;
						}
					goodsService.getGoogsListInit($scope.pId,$scope.pageSize,$scope.param,function(data){
						$scope.topList=data.data;
						if($scope.topList!=null){
							goodsService.getPxByPId($scope.topList[0].id,function(data){
								$scope.pxList=data.data;
							},error);
						}
					},error)
				}
				mui.init();
				
				(function($) {
					//阻尼系数
					/*var deceleration = mui.os.ios?0.003:0.0009;
					$('.mui-scroll-wrapper').scroll({
						bounce: false,
						indicators: true, //是否显示滚动条
						deceleration:deceleration
					});*/
					
					$.ready(function() {
						//循环初始化所有下拉刷新，上拉加载。
						
							
						$scope.openPx=function(){
							var id = document.getElementsByClassName('aaa')[0].getElementsByClassName('mui-active')[0].getAttribute('val');
							$scope.index=id;
							
							var styleId=$scope.topList[$scope.index].id;
							goodsService.getPxByPId(styleId,function(data){
								$scope.pxList=data.data;
								mui("#popover").popover('toggle', document.getElementById("div"));  
							},error);
							//调用隐藏/显示弹出层  
						}
						$scope.goodPx="";
						mui(".aaa").on('tap','.mui-active',function(){
						 var id =this.name;
						}) 
						$scope.checkPx=function(id){
							var idNum = document.getElementsByClassName('aaa')[0].getElementsByClassName('mui-active')[0].getAttribute('val');
							$scope.index=idNum;
						//	mui("#popover").popover('toggle', document.getElementById("div")); 
							$scope.goodPx=id;
							getList(true);
						}
						$scope.topList=[{'id':'item1mobile',"title":"推荐 "}];//初始化数据启动滑屏
						
						$scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
							$.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) {
								$(pullRefreshEl).pullToRefresh({
									up: {
										callback: function() {
											var self = this;
											setTimeout(function() {
												var ul = self.element.querySelector('.mui-table-view');
												$scope.index=index;
												getList(false,self);
												self.endPullUpToRefresh();
											}, 1000);
										}
									}
								});
								
							});
							var deceleration = mui.os.ios?0.003:0.0009;
							$('.mui-scroll-wrapper').scroll({
								bounce: false,
								indicators: true, //是否显示滚动条
								deceleration:deceleration
							});
						});
						$scope.initIndex=0;
						var startNum=0;
						var getList=function(ifSearch){
							if(ifSearch){
								startNum=0;
							}else{
								startNum=$scope.topList[$scope.index].goodsList.length;
							}
							var styleId=$scope.topList[$scope.index].id;
							$scope.searchTitle=document.getElementById("searchTitle").value;
							$scope.searchParam={"checkStatus":'1',"title":$scope.searchTitle};
							$scope.searchParam.gstyle=styleId;
							if($scope.goodPx!=""){
								$scope.searchParam.px=$scope.goodPx;
							}
							//请求商品列表数据
							goodsService.getGoogsListSH(startNum,$scope.pageSize,$scope.searchParam,function(data){
								if(startNum==0){
									$scope.topList[$scope.index].goodsList=data.data.list;
								}else{
									angular.forEach(data.data.list, function(goods) {
										$scope.topList[$scope.index].goodsList.push(goods);
									});
								}
								
							},error) ;
						};
						
						$scope.searchBtnClick=function(){
							var id = document.getElementsByClassName('aaa')[0].getElementsByClassName('mui-active')[0].getAttribute('val');
							$scope.index=id;
							console.info($scope.index);
							//window.scrollTo(0,260);
							//var id=$scope.topList[$scope.index].id;
							//alert(id);
							//document.getElementById(id+"_scroll").Scroll().scrollTo(0,0);
							getList(true);
						}
						  
						
						$scope.goodsDetailPage=function(goodsId){
							mui.openWindow({
								url:"goodsDetails.html",
								id:'goodsDetails'+new Date().getMilliseconds(),
							    extras:{
							        goodsId:goodsId
							    },
							    styles: {
									popGesture:"close"	
								}
							});
						}
						agentService.getAgentByUser(function(data){
							$scope.agent=data.data;
						},error);
						
//						$scope.getImage=function(url){
//							console.info(url);
//						}
						
					});
				})(mui);
			});
			
		</script>
	</body>
</html>